package com.czh.springboot04.MyController;

import com.czh.springboot04.entity.Coursecollection;
import com.czh.springboot04.service.CoursecollectionService;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/coursecollection")
@CrossOrigin
public class CoursecollectionController {
    @Autowired
    private CoursecollectionService coursecollectionService;

    @GetMapping("/selectCoursemark")
    public R selectCoursemark(int pageNum, int pageSize, String nickName, String courseName) {
        PageInfo<Coursecollection> coursemark = coursecollectionService.selectCoursemark(pageNum, pageSize, nickName, courseName);
        if (coursemark != null) {
            return R.ok(coursemark);
        }else {
            return R.error("查询失败");
        }
    }

    @GetMapping("/selectCoursemarkByUserIdAndKcid")
    public R selectCoursemarkByUserIdAndKcid(int userId, int kcid) {
        Coursecollection coursecollection = coursecollectionService.selectCoursemarkByUserIdAndKcid(userId, kcid);
        if (coursecollection!= null) {
            return R.ok(coursecollection);
        }else {
            return R.error("查询失败");
        }
    }

    @GetMapping("/insertCoursecollection")
    public R insertCoursecollection( int userid, int kcid) {
        int i = coursecollectionService.insertCoursecollection(userid, kcid);
        if (i>0) {
            return R.ok("添加成功");
        }else {
            return R.error("添加失败");
        }
    }

    @GetMapping("/deleteCoursecollection")
    public R deleteCoursecollection(int userid, int kcid) {
        int i = coursecollectionService.deleteCoursecollection(userid, kcid);
        if (i>0) {
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }
    }
}
